import json
from datetime import datetime

COMCODE = {
    "exit": -1,
    "server_text": 0,
    "customer_text": 1,
    "server_file": 2,
    "customer_file": 3,
    "login": 4,
    "register": 5,
    "user_list": 6,
    "friend_list": 7,
    "add_friend": 8,
    "del_friend": 9,
    "success": 200,
    "fail": 400,
}


# @contextmanager
def process_logger(func):
    def wrapper(*args, **kwargs):
        print("Processing", func.__name__)
        return func(*args, **kwargs)

    return wrapper


class DateEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime):
            return obj.strftime("%Y-%m-%d %H:%M:%S")
        else:
            return json.JSONEncoder.default(self, obj)